package instgram

import (
	"encoding/json"
)

/*
{
  "country_codes": "[{\"country_code\":\"86\",\"source\":[\"default\"]}]",
  "phone_id": "7e316521-3214-435e-992e-522ed304e59e",
  "q": "8615019285799",
  "guid": "c3d0ce4c-c663-4f15-bbe5-7b895488296f",
  "device_id": "android-ccd0ec1b97d99911",
  "android_build_type": "release",
  "waterfall_id": "22c64c46-b101-4290-8360-279c5f36d262",
  "directly_sign_in": "true",
  "is_wa_installed": "true"
}
*/

type InsRequestData struct {
	CountryCodes     string `json:"country_codes"`
	PhoneId          string `json:"phone_id"`
	Q                string `json:"q"`
	Guid             string `json:"guid"`
	DeviceId         string `json:"device_id"`
	AndroidBuildType string `json:"android_build_type"`
	WaterfallId      string `json:"waterfall_id"`
	DirectlySignIn   string `json:"directly_sign_in"`
	IsWaInstalled    string `json:"is_wa_installed"`
}

func NewInsRequestData(number string, areaCode string) *InsRequestData {
	length := len(areaCode)
	codesBean := CountryCodes{
		CountryCode: number[0:length],
		Source:      []string{"default"},
	}

	dataBean := &InsRequestData{
		CountryCodes:     codesBean.ToString(),
		PhoneId:          "",
		Q:                number,
		Guid:             "",
		DeviceId:         "",
		AndroidBuildType: "release",
		WaterfallId:      "",
		DirectlySignIn:   "true",
		IsWaInstalled:    "false",
	}
	return dataBean
}

type CountryCodes struct {
	CountryCode string   `json:"country_code"`
	Source      []string `json:"source"`
}

func (cc *CountryCodes) ToString() string {
	bytes, _ := json.Marshal(cc)
	return "[" + string(bytes) + "]"
}
